//
//  FCStoreObserve.m
//  IAPTest
//
//  Created by mac on 12-4-13.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "FCStoreObserve.h"

@implementation FCStoreObserve

-(void) paymentQueue:(SKPaymentQueue *)queue removedTransactions:(NSArray *)transactions{
}
-(void) paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
    for (SKPaymentTransaction *tran in transactions)   {
        switch (tran.transactionState) {
            case SKPaymentTransactionStatePurchased:
                NSLog(@"Purchased");
                [self completeTransaction:tran];
                break;
            case SKPaymentTransactionStatePurchasing:
                NSLog(@"Purchasing");
                break;
            case  SKPaymentTransactionStateRestored:
                NSLog(@"Restored");
                break;
            case SKPaymentTransactionStateFailed:
                NSLog(@"Failed");
                [self failedTransaction:tran];
                break;
            
            default:
                break;
        }
    }
}
- (void) completeTransaction: (SKPaymentTransaction *)transaction{
    NSLog(@"class = %@ selector = %@",NSStringFromClass([self class]),NSStringFromSelector(_cmd));//;
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}

-(void) PurchasedTransaction: (SKPaymentTransaction *)transaction{
      NSLog(@"class = %@ selector = %@",NSStringFromClass([self class]),NSStringFromSelector(_cmd));
}
- (void) failedTransaction: (SKPaymentTransaction *)transaction{
    
    if (transaction.error.code != SKErrorPaymentCancelled) {
        // Optionally, display an error here.
    }
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
    
      NSLog(@"class = %@ selector = %@",NSStringFromClass([self class]),NSStringFromSelector(_cmd));
}
-(void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue{
      NSLog(@"class = %@ selector = %@",NSStringFromClass([self class]),NSStringFromSelector(_cmd));
}
-(void) paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error{
      NSLog(@"class = %@ selector = %@",NSStringFromClass([self class]),NSStringFromSelector(_cmd));
    
    NSLog(@"error = %@",error );
}


@end
